#ifndef MLOADER_LOADER
#define MLOADER_LOADER

#include "Export/Model.hpp"
#include "Core/Path.h"

#define ML_REGISTER(CLASS_NAME) LoaderAutoRegister GLoader##CLASS_NAME(#CLASS_NAME,[](){ return new CLASS_NAME(); });

namespace MLoader
{
    class IOStream;
    class Loader
    {
    public:
        static std::unordered_map<std::string, std::function<Loader*()>> Factory;
                
        static Loader* GetLoader(const std::string& type) {
            return Factory[type]();
        }
        
    public:
        virtual ~Loader(){ }
        
        virtual Model* LoadFile(const std::string& file_path);
        virtual bool CanLoad(const Path& p) const = 0;
        virtual Model* ReadStream(IOStream& stream, const Path& p) = 0;
    };

    class LoaderAutoRegister
    {
    public:
        LoaderAutoRegister(const std::string& type, const std::function<Loader*()>&& callback) {
            Loader::Factory.emplace(type, callback);
        }
    };
}

#endif // MLOADER_LOADER
